package com.zjxh.zjxh.common.util;

import cn.hutool.core.util.StrUtil;
import java.time.LocalDate;
import lombok.extern.slf4j.Slf4j;

/**
 * @author: Oyp
 * @date: 2021/1/14 on 10:26 上午
 * @desc:
 */
@Slf4j
public class GlobalUtil {
  public static String toGender(Integer gender) {
    // 性别0保密1男2女
    switch (gender) {
      case 0:
        return "保密";
      case 1:
        return "男";
      case 2:
        return "女";
      default:
        return "未知";
    }
  }

  /**
   * 订单类型：0派送，1自取
   *
   * @param orderType
   * @return
   */
  public static String toOrderType(Integer orderType) {
    switch (orderType) {
      case 0:
        return "快递";
      case 1:
        return "自取";
      default:
        return "未知";
    }
  }

  /**
   * 是、否
   *
   * @param hasMarriage
   * @return
   */
  public static String toHasMarriage(Boolean hasMarriage) {
    if (hasMarriage == null) {
      return "未知";
    }
    if (hasMarriage) {
      return "已婚";
    } else {
      return "未婚";
    }
  }

  public static String toPatientsInfo(String username, Integer gender, LocalDate birthday) {
    return username
        + " "
        + (toGender(gender))
        + " "
        + birthday.until(LocalDate.now()).getYears()
        + "岁";
  }

  public static String getUsernameByPatientsInfo(String patientsInfo) {
    if (StrUtil.isBlank(patientsInfo)) {
      return null;
    }
    return patientsInfo.substring(0, patientsInfo.indexOf(" "));
  }

  public static String getGenderByPatientsInfo(String patientsInfo) {
    if (StrUtil.isBlank(patientsInfo)) {
      return null;
    }
    return patientsInfo.substring(patientsInfo.indexOf(" ") + 1, patientsInfo.lastIndexOf(" "));
  }

  public static String getGenderAgeByPatientsInfo(String patientsInfo) {
    if (StrUtil.isBlank(patientsInfo)) {
      return null;
    }
    return patientsInfo.substring(patientsInfo.indexOf(" ") + 1);
  }

  public static String getAgeByPatientsInfo(String patientsInfo) {
    if (StrUtil.isBlank(patientsInfo)) {
      return null;
    }
    return patientsInfo.substring(patientsInfo.lastIndexOf(" ") + 1);
  }

  public static Integer getIntAgeByPatientsInfo(String patientsInfo) {
    if (StrUtil.isBlank(patientsInfo)) {
      return null;
    }
    return Integer.valueOf(
        patientsInfo.substring(patientsInfo.lastIndexOf(" ") + 1, patientsInfo.length() - 1));
  }
}
